package com.lzk.order.controller;

import com.lzk.basic.util.JsonResult;
import com.lzk.basic.util.LogininfoContext;
import com.lzk.basic.util.PageList;
import com.lzk.order.domain.OrderPetAcquisition;
import com.lzk.order.dto.OrderDto;
import com.lzk.order.query.OrderPetAcquisitionQuery;
import com.lzk.order.service.IOrderPetAcquisitionService;
import com.lzk.org.domain.Department;
import com.lzk.user.domain.LoginInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetAcquisitionController {

    @Resource
    private IOrderPetAcquisitionService orderPetAcquisitionService;


    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "取消订单" )
    @DeleteMapping("/{id}")
    public JsonResult cancel(@PathVariable("id") Long id){
        try {
            orderPetAcquisitionService.cancel(id);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return  JsonResult.me(false,"操作失败");
        }
    }

    @ApiOperation(value = "订单确认" )
    @PostMapping("/confirm")
    public JsonResult confirm(@RequestBody OrderDto dto){
        try {
            orderPetAcquisitionService.confirm(dto);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me(false,"确认订单失败");
        }
    }


    /**
     * 分页查询或高级查询
     * @param query
     * @return
     */
    @ApiOperation(value = "分页查询或高级查询" )
    @PostMapping
    public PageList<OrderPetAcquisition> queryPage(@RequestBody OrderPetAcquisitionQuery query, HttpServletRequest request){
        LoginInfo logininfo = LogininfoContext.getLogininfo(request);
        Long id = logininfo.getId();
        return orderPetAcquisitionService.queryData(query,id);
    }


}
